package com.wl.Websocket;

import com.wl.Websocket.bean.WebSocketProperties;
import com.wl.Websocket.biz.DefaultMsgSender;
import com.wl.Websocket.biz.IMsgSender;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;

@AutoConfiguration
@ComponentScan("com.wl.Websocket")
@EnableConfigurationProperties(WebSocketProperties.class)
@ConditionalOnProperty(prefix = "websocket", name = "enable")
public class WebSocketAutoConfiguration {

    @Bean
    public ServerEndpointExporter serverEndpointExporter(){
        return new ServerEndpointExporter();
    }

    @Bean
    @ConditionalOnMissingBean
    public IMsgSender msgSender(){
        return new DefaultMsgSender();
    }

}
